<template>
  <div class="a1">
    <div class="login-page">
      <header class="header">
        <span class="back-arrow" @click="$router.push('/Help')">←</span>
      </header>
      <div class="login-form">
        <h1 class="title">锁定账号</h1>
        <div class="input-group">
          <select class="country-code">
            <option value="+86">+86</option>
          </select>
          <input type="text" class="phone-input" placeholder="请输入手机号" v-model="form.phone"
                 @input="validatePhoneNumber"/>
          <p v-if="isPhoneNumberValid" class="valid-message">手机号有效</p>
          <p v-if="!isPhoneNumberValid && form.phone !== ''" class="invalid-message">手机号无效，请输入正确的手机号</p>
        </div>
        <button :disabled="!isPhoneNumberValid ||isLoginButtonDisabled" class="sms-button" @click="login">锁定账号</button>
      </div>
    </div>
  </div>
</template>


<script>
export default {
  data() {
    return {
      form: {
        phone: '',
      },
      isPhoneNumberValid: null, // 验证结果，null表示未验证，true表示验证通过，false表示验证失败
      isLoginButtonDisabled: false, // 控制登录按钮是否禁用
    };
  },
  methods: {
    validatePhoneNumber() {
      const phoneRegex = /^1[3-9]\d{9}$/;
      this.isPhoneNumberValid = phoneRegex.test(this.form.phone);
    },
    login() {
      if (this.isPhoneNumberValid) {
        this.axios.post(`http://localhost:9000/user/disableUser/${sessionStorage.getItem('satoken')}`, this.form).then(res => {
          if (res.data.code === 200) {
            // sessionStorage.removeItem("satoken")
            this.$router.push("/Help");
          } else {
            alert(res.data.data);
          }
        });
      }
    }
  },
  watch: {
    'form.phone': function(newVal) {
      if (newVal === '') {
        this.isPhoneNumberValid = null;
      } else {
        this.validatePhoneNumber();
      }
    },
    'form.password': function(newVal) {
      if (newVal === '') {
        this.isPasswordValid = null;
      } else {
        this.validatePassword();
      }
    }
  }
};
</script>



<style scoped>
.login-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background-color: #f9f9f9;
}

.login-page {
  width: 100%;
  height: 100%;
  max-width: 400px; /* 设定最大宽度 */
  padding: 20px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  background-color: #fff;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.back-arrow {
  font-size: 24px;
  cursor: pointer;
}

.help {
  font-size: 14px;
}

.title {
  font-size: 24px;
  font-weight: bold;
  text-align: left;
  margin-bottom: 20px;
}

.agreement {
  text-align: center;
  margin: 5px 0;
}

.input-group {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 10px;
  margin-top: 20px;
}

.country-code {
  width: 50px;
  height: 40px;
  border: 1px solid #ccc;
  border-radius: 5px;
}

.phone-input {
  flex: 1;
  height: 40px;
  margin: 5px;
  padding: 0 10px;
  border: 1px solid #ccc;
  border-radius: 5px;
}

.phone-input2 {
  width: 76%;
  flex: 1;
  height: 40px;
  margin: 5px 0;
  padding: 0 10px;
  border: 1px solid #ccc;
  border-radius: 5px;
}

.country-code2{
  width: 15%;
  height: 40px;
  font-size: 11px;
  padding: 10px 0;
  border: 1px solid #ccc;
  border-radius: 5px;
}
.sms-button {
  width: 100%;
  padding: 10px;
  margin: 10px 0;
  background-color: #ccc;
  border: none;
  border-radius: 5px;
  cursor: pointer;
}

.sms-button:disabled {
  background-color: #eee;
}

.other-login-options {
  display: flex;
  justify-content: space-between;
  margin-top: 10px;
}

.other-button {
  flex: 1;
  padding: 10px;
  margin: 5px;
  background-color: #f5f5f5;
  border: none;
  border-radius: 5px;
  cursor: pointer;
}

.note {
  text-align: left;
  font-size: 12px;
  color: #888;
  margin-bottom: 15px;
}
</style>
